<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>商品管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
	<style>
	#ggnamediv .layui-input,#ggvaldiv .layui-input{ display:inline;height:30px}
	</style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-card layui-col-md12">
				<div class="layui-card-header">
					{if !$info['id']}<i class="fa fa-plus"></i> 添加商品{else}<i class="fa fa-pencil"></i> 编辑商品{/if}
					<i class="layui-icon layui-icon-close" style="font-size:18px;font-weight:bold;cursor:pointer" onclick="closeself()"></i>
				</div>
				<div class="layui-card-body" pad15>
					{if $info['ischecked']==2}<blockquote class="layui-elem-quote" style="color:red">商品未审核通过，驳回原因：{$info.check_reason}</blockquote>{/if}
					<div class="layui-form">
									<input type="hidden" name="id" value="{$info['id']}"/>
									{if input('param.bid')}<input type="hidden" name="info[bid]" value="{$Request.param.bid}"/>{/if}
									<div class="layui-form-item">
										<label class="layui-form-label">商品名称：</label>
										<div class="layui-form-mid">{$info['name']}</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">商品主图：</label>
										<div id="picPreview" style="padding-top:10px;padding-left:110px;">
											<div class="layui-imgbox" style="width:100px;"><div class="layui-imgbox-img"><img src="{$info['pic']}"/></div></div>
										</div> 
									</div>
									{if $info['sellpoint']}
									<div class="layui-form-item">
										<label class="layui-form-label">商品卖点：</label>
										<div class="layui-form-mid">{$info['sellpoint']}</div>
									</div>
									{/if}
									<div class="layui-form-item">
										<label class="layui-form-label">商品分类：</label>
										<div class="layui-input-inline" style="width:400px">
											<select name="info[cid]" id="cid" xm-select="selectCid" xm-select-max="5" xm-select-search >
											<option value="">--请选择--</option>
											{foreach $clist as $cv}
												<option value="{$cv['id']}" {if in_array($cv['id'],$info['cid'])}selected{/if}>{$cv['name']}</option>
												{foreach $cv['child'] as $k=>$v}
												{if $k < count($cv['child'])-1}
												<option value="{$v['id']}" {if in_array($v['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;├ {$v['name']}</option>
												{else}
												<option value="{$v['id']}" {if in_array($v['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;└ {$v['name']}</option>
												{/if}
													{foreach $v['child'] as $k2=>$v2}
													{if $k2 < count($v['child'])-1}
													<option value="{$v2['id']}" {if in_array($v2['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├ {$v2['name']}</option>
													{else}
													<option value="{$v2['id']}" {if in_array($v2['id'],$info['cid'])}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└ {$v2['name']}</option>
													{/if}
													{/foreach}
												{/foreach}
											{/foreach}
											</select>
										</div>
										<div class="layui-form-mid layui-word-aux">最多可选5个分类</div>
										<!-- <div class="layui-form-mid layui-word-aux"><a href="categoryadd.php">创建分类</a></div> -->
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">商品分组：</label>
										<div class="layui-input-inline" style="width:600px">
											{php} $gids = explode(',',$info['gid']);{/php}
											{foreach $glist as $g}<input type="checkbox" name="info[gid][]" value="{$g['id']}" {if in_array($g['id'],$gids)}checked{/if} title="{$g['name']}" lay-skin="primary">{/foreach}
										</div>
										<!-- <div class="layui-form-mid layui-word-aux"><a href="groupadd.php">创建分组</a></div> -->
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">销量：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[sales]" value="{$info['id']?$info['sales']:'0'}" class="layui-input">
											<input type="hidden" name="info[oldsales]" value="{$info['id']?$info['sales']:'0'}" class="layui-input">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">库存：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[stock]" value="{$info['stock']}" class="layui-input">
										</div>
									</div>
									<div class="layui-form-item">
										<label class="layui-form-label">序号：</label>
										<div class="layui-input-inline">
											<input type="text" name="info[sort]" value="{$info['sort']?$info['sort']:'0'}" class="layui-input">
										</div>
										<div class="layui-form-mid layui-word-aux">用于排序,越大越靠前</div>
									</div>
									

									<div class="layui-form-item">
										<label class="layui-form-label">状态：</label>
										<div class="layui-input-inline" style="width:600px">
											<input type="radio" name="info[status]" value="1" title="已上架" {if !$info['id'] || $info['status']==1}checked{/if} lay-filter="set_status"/>
											<input type="radio" name="info[status]" value="0" title="未上架" {if $info['id'] && $info['status']==0}checked{/if} lay-filter="set_status"/>
											<input type="radio" name="info[status]" value="2" title="设置上架时间" {if $info['id'] && $info['status']==2}checked{/if} lay-filter="set_status"/>
											<input type="radio" name="info[status]" value="3" title="设置上架周期" {if $info['id'] && $info['status']==3}checked{/if} lay-filter="set_status"/>
										</div>
									</div>
									
									<div class="layui-form-item" id="set_status2" {if $info['status']!=2}style="display:none"{/if}>
										<label class="layui-form-label">上架时间：</label>
										<div class="layui-input-inline" style="width:150px">
											<input type="text" name="info[start_time]" class="layui-input" value="{$info.start_time}" id="start_time" autocomplete="off">
										</div>
										<div class="layui-form-mid">到</div>
										<div class="layui-input-inline" style="width:150px">
											<input type="text" name="info[end_time]" class="layui-input" value="{$info.end_time}" id="end_time" autocomplete="off">
										</div>
										<div class="layui-form-mid layui-word-aux" style="clear:left;margin-left:110px"></div>
									</div>
									<div class="layui-form-item" id="set_status3" {if $info['status']!=3}style="display:none"{/if}>
										<label class="layui-form-label">上架周期：</label>
										<div class="layui-input-inline" style="width:150px">
											<input type="text" name="info[start_hours]" class="layui-input" value="{$info.start_hours}" id="start_hours" autocomplete="off">
										</div>
										<div class="layui-form-mid">到</div>
										<div class="layui-input-inline" style="width:150px">
											<input type="text" name="info[end_hours]" class="layui-input" value="{$info.end_hours}" id="end_hours" autocomplete="off">
										</div>
										<div class="layui-form-mid layui-word-aux" style="clear:left;margin-left:110px">结束时间小于或等于开始时间表示跨天,如:16:00到06:00表示下午4点到次日早晨6点</div>
									</div>
									<div class="layui-form-item">
										<div class="layui-input-block">
											<button class="layui-btn layui-btn-danger" lay-submit lay-filter="formsubmit">提 交</button>
										</div>
									</div>
					</div>
				</div>
			</div>
		</div>
  </div>
	
	{include file="public/js"/}
	<video id="myvideo" style="display:none"></video>
	<script>
		
	layui.form.on('radio(set_status)',function(data){
		if(data.value=="0" || data.value=="1"){
			$('#set_status2').hide();
			$('#set_status3').hide();
		}
		if(data.value=="2"){
			$('#set_status2').show();
			$('#set_status3').hide();
		}
		if(data.value=="3"){
			$('#set_status2').hide();
			$('#set_status3').show();
		}
	});
	
	layui.laydate.render({ 
		elem: '#start_hours',
		type: 'time',
		format:'HH:mm',
		trigger: 'click'
	});
	layui.laydate.render({ 
		elem: '#end_hours',
		type: 'time',
		format:'HH:mm',
		trigger: 'click'
	});
	layui.laydate.render({ 
		elem: '#start_time',
		type: 'datetime',
		trigger: 'click'
	});
	layui.laydate.render({ 
		elem: '#end_time',
		type: 'datetime',
		trigger: 'click'
	});

	layui.form.on('switch(isfuwu)',function(data){
		if(data.elem.checked){
			$('#isfuwudiv').show();
		}else{
			$('#isfuwudiv').hide();
		}
	})
	layui.form.on('radio(commissionset)', function(data){
		if(data.value == '1'){
			$('#commissionset1').show();
			$('#commissionset2').hide();
			$('#commissionset3').hide();
		}else if(data.value == '2'){
			$('#commissionset1').hide();
			$('#commissionset2').show();
			$('#commissionset3').hide();
		}else if(data.value == '3'){
			$('#commissionset1').hide();
			$('#commissionset2').hide();
			$('#commissionset3').show();
		}else{
			$('#commissionset1').hide();
			$('#commissionset2').hide();
			$('#commissionset3').hide();
		}
	});
	layui.form.on('radio(scoredkmaxset)', function(data){
		if(data.value == '1'){
			$('#scoredkmaxset1').show();
			$('#scoredkmaxunit').html('%');
		}else if(data.value == '2'){
			$('#scoredkmaxset1').show();
			$('#scoredkmaxunit').html('元');
		}else{
			$('#scoredkmaxset1').hide();
		}
	})
		function gonext(layid){
			$(window).scrollTop(0);
			layui.element.tabChange('mytab', layid);
		}
		layui.element.on('tab(mytab)', function(){
			try{
				changeconentxy();
			}catch(e){}
		})
		
		layui.form.on('checkbox(gettjset)', function(data){
			console.log(data)
			if(data.elem.checked){
				$('#gettjset').hide();
			}else{
				$('#gettjset').show();
			}
		});
		var chooseUrlField = '';
		function chooseUrl2(field){
			chooseUrlField = field;
			layer.open({type:2,shadeClose:true,area:['1100px', '650px'],'title':'选择链接',content:"{:url('DesignerPage/chooseurl')}&callback=chooseLink2"})
		}
		function chooseLink2(urlname,url){
			$("#"+chooseUrlField).val(url);
		}

		function showChooseCategory(){
			layer.open({type:2,title:'选择类目',content:"{:url('Wxvideo/allcategory')}&ischoose=1",area:['900px','600px'],shadeClose:true});
		}
		function chooseCategory(data){
			console.log(data)
			$("input[name='info[wxvideo_third_cat_id]']").val(data.third_cat_id);
		}
		</script>

	<script>
	layui.form.on('submit(formsubmit)', function(obj){
		var field = obj.field
		//field['info[detail]'] = ueditor.getContent();
		//console.log(field);return;
		if(field['info[freighttype]'] == 0 && field['info[freightdata]'] == ''){
			dialog('请选择运费模板');
			return;
		}
		var index = layer.load();
		$.post("{:url('save')}",field,function(data){
			layer.close(index);
			dialog(data.msg,data.status);
			if(data.status == 1){
				setTimeout(function(){
					parent.layer.closeAll();
					parent.tableIns.reload()
				},1000)
			}
		})
	})
  </script>
	{include file="public/copyright"/}
</body>
</html>